

import pygame

import context

class Win(context.Context):
    
    def __init__(self):
        self.screen = pygame.display.get_surface()
        
        font = pygame.font.Font(None, 60)
        lines = ["You WIN", "press return to continue..."]
        self.sprites = []
        posx = self.screen.get_rect().centerx
        dy = self.screen.get_rect().height / (len(lines) + 2)
        posy = dy
        for member in lines:
            spr = pygame.sprite.Sprite()
            spr.image = font.render(member , True, pygame.Color('yellow'), pygame.Color('lightblue'))
            spr.rect = spr.image.get_rect(center=(posx, posy))
            posy += dy
            self.sprites.append(spr)
        
    def think(self):
        """Called once per frame"""
        self.get_input()
        self.update()

    def resume(self):
        """Called when an already-existing context is again at the top of the stack"""
        pass

    def get_input(self):
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                context.pop()
            elif e.type == pygame.KEYDOWN:
                if e.key == pygame.K_RETURN:
                    context.pop()
                
    def update(self):
        for spr in self.sprites:
            self.screen.blit(spr.image, spr.rect)
        pygame.display.flip()
                